package com.ruixun.shopmanagement.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruixun.shopmanagement.dao.ProductMapper;
import com.ruixun.shopmanagement.entity.Page;
import com.ruixun.shopmanagement.entity.Product;
import com.ruixun.shopmanagement.service.inter.ProductService;

@Service
public class ProductServiceImpl implements ProductService{
	@Autowired
	ProductMapper productMapper;
	
	@Override
	public List<Product> selectHotTop10Produce() {
		// TODO Auto-generated method stub
		return productMapper.selectHotProductList(0, 10);
	}

	@Override
	public Page findProductList(Integer cid,Integer targetPage) {
		Page page=new Page();
		int pagesize=page.getPageSize();
		List<Product> list=productMapper.selectProductList(cid, (targetPage-1)*pagesize,pagesize );;
		page.setList(list);
		page.setTotalCount(productMapper.selectTotoalCountByCid(cid));
		page.setCurrPage(targetPage);
		int totalPage=page.getTotalCount()%page.getPageSize()==0?page.getTotalCount()/page.getPageSize():page.getTotalCount()/page.getPageSize()+1;
		page.setTotalPage(totalPage);
		return page;
	}

	@Override
	public Product getProductById(String pid) {
		// TODO Auto-generated method stub
		return productMapper.selectProductBypid(pid);
	}
	
}
